package com.simple.common.entity.req.india.req;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.function.Consumer;

/**
 * 跳转支付
 *
 * @author yasud
 * @date 2020年09月28日 17:58
 * @description
 */
@Data
public class IndiaWithdrawalReq extends WithdrawalBase {


    /**
     * 发起人
     */
    private String originator;

    /**
     * 支行
     */
    private String subbranch;

    /**
     * 定义常量
     */
    public static  final String BANK = "1", WALLET = "2";


    @Override
    public void check(Consumer<IndiaReqBase>... consumers) {
        Preconditions.checkNotNull(getExtraInfo(), "extraInfo is empty");
        Preconditions.checkState(getTransferAmount().indexOf(".") != -1, "amount format error");
        String substring = getTransferAmount().substring(getTransferAmount().indexOf(".") + 1);
        Preconditions.checkState(substring.length() == 2, "amount format error");
        if (StringUtils.equalsIgnoreCase(BANK, getTransferType())) {
            Preconditions.checkState(StringUtils.isNotBlank(getPayeeName()), "payeeName is empty");
            Preconditions.checkState(StringUtils.isNotBlank(getSubbranch()), "subbranch is empty");
            Preconditions.checkState(StringUtils.isNotBlank(getBankName()), "bankName is empty");
//            Preconditions.checkState(StringUtils.isNotBlank(getBankCode()), "bankCode is empty");
        }
        super.check();
    }


    @Override
    protected Map<String, Consumer<Object>> predicateMapping() {
        Map<String, Consumer<Object>> of = ImmutableMap.of(
                "email", o -> {
                    Preconditions.checkNotNull(o, "email is empty");
                },
                "mobile", o -> {
                    Preconditions.checkNotNull(o, "mobile is empty");
                },
                "ipAddress", o -> {
                    Preconditions.checkNotNull(o, "ipAddress  is empty");
                },
                "province", o -> {
                    Preconditions.checkNotNull(o, "province  is empty");
                },
                "city", o -> {
                    Preconditions.checkNotNull(o, "city  is empty");
                }
        );
        return of;
    }
}
